package com.kkb.pojo;

/**
 * 页面相关属性
 */
public class Page {
    // 当前页码
    private int pageIndex;
    // 每页行数
    private int pageSize;
    // 总页数
    private int totalPage;
    // 总行数
    private int total;

    public Page() {
        this.pageIndex = 1;
        this.pageSize = 5;
    }

    public Page(int pageIndex, int pageSize) {
        assert pageIndex > 0;
        assert pageSize != 0;
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        calculateTotalPage();
    }

    public int getTotalPage() {
        return this.totalPage;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
        calculateTotalPage();
    }

    private void calculateTotalPage() {
        totalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
    }

    /**
     * 当前页面首行数据的序号
     */
    public int getPageFirst() {
        return (pageIndex - 1) * pageSize;
    }
}
